package com.xuan.mail.controller;


import com.xuan.mail.domin.Contact;
import com.xuan.mail.domin.Groupm;
import com.xuan.mail.service.ContactGroupService;
import com.xuan.mail.service.ContactService;
import com.xuan.mail.service.GroupmService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@CrossOrigin
@RestController
@RequestMapping("contact")
public class ContactController {
    @Resource
    private ContactService contactService;
    @Resource
    private GroupmService groupService;
    @Resource
    private ContactGroupService contactGroupService;

    //获得当前组别的通讯列表

    @GetMapping("/group_list")
    public List<Contact>  getContactByGroupId(Integer groupId){
        return contactService.getContactByGroupId(groupId);
    }
   //当前用户的所有通讯列表
    @GetMapping("/all_list")
    public List<Contact>  getContactAll(Integer userId){
        return contactService.getContactAll(userId);
    }
    //添加通讯
    @PostMapping("/add")
    public String add(@RequestBody Contact contact, Integer groupId){

        contactService.addContact(contact,groupId);
        System.out.println(contact);

        return "添加成功";
    }
    //获得通讯分组
    @GetMapping("/group")
    public List<Groupm> getGroup(Integer userId){
        return groupService.getGroup(userId);
    }
    //根据联系人ID获取联系人组别
    @GetMapping("/group_name")
    public Groupm getGroupByContactId(Integer contactId){
        return contactService.getGroupByContactId(contactId);
    }
    //根据Id获取联系人信息
    @GetMapping("/get_contact")
    public Contact getContactById(Integer contactId){
        return contactService.getContactById(contactId);
    }
    //根据组别ID获取组别信息
    @GetMapping("/get_group")
    public Groupm getGroupById(Integer groupId){
        return groupService.getGroupById(groupId);
    }
    //添加通讯录分组
    @PostMapping("/add_group")
    public String addGroup(@RequestBody Groupm groupm){
        System.out.printf(String.valueOf(groupm));
        groupService.addGroup(groupm);
        return "添加成功";
    }
    //逻辑删除通讯分组
    @GetMapping("/logic_delete_group")
    public String logicDeleteGroup(Integer groupId){
        groupService.logicDeleteGroup(groupId);
        return "逻辑删除成功";
    }
    //删除通讯分组
    @GetMapping("/delete_group")
    public String deleteGroup(Integer groupId){
        groupService.deleteGroup(groupId);
        return "删除成功";
    }
    //修改通讯分组
    @PostMapping("/update_group")
    public String updateGroup(@RequestBody Groupm groupm){
        groupService.updateGroup(groupm);
        return "修改成功";
    }
    //删除通讯（逻辑删除）
    @GetMapping("/logic_delete")
    public String delete(Integer contactId){

        contactService.logicdeleteContact(contactId);
        return "逻辑删除成功";
    }

    //删除通讯（物理删除）
    @GetMapping("/physics_delete")
    public String physics_delete(Integer contactId){
        contactService.deleteContact(contactId);
        return "删除成功";
    }

    //修改通讯
    @PostMapping("/update")
    public String update(@RequestBody Contact contact,Integer groupId){
        contactService.updateContact(contact,groupId);
        return "修改成功";
    }

}